<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class LoginProcess extends CI_Controller {
function __construct()
    {
        parent::__construct();
    	$this->load->library('session');
		$this->load->helper('url');

	}
	
	
	function index()
	{
		
		$this->login();
	}

	public function login()
	{
		$date=array("message"=>"");
		$this->load->view("client/login",$date);
	}
	
	
	
	
	function loginpro()
			{
			$this->session->unset_userdata('clientcode');
		if($this->session->userdata("clientcode")==false)
			{
				$post=$this->input->get_post("login");
				$name=$post["username"];
				$pw=$post["password"];
				if($name&&$pw)
					{
							$this->load->model("modlogin");
							$rows=$this->modlogin->db_auth_login_client($name,$pw);
							
							if(count($rows)>0)
							{
	
								if(count($rows)==1)
								{
									foreach($rows as $r)
										{
											$info=array("id"=>$r->idclient,"clientcode"=>$r->clientcode,"username"=>$r->username,"role"=>"client");
											$this->session->set_userdata($info);
									
										}
										$data=array("name"=>$info["username"]);
//enter page CMS	
										redirect("client/product/mainpage","reflesh");
											//echo $this->session->userdata("username");
								
						
								}else//not login in
									{
										$date=array("message"=>"Your User Name or PassWord isn't correct!1")	;								
										$this->load->view("client/login",$date);
									}
				
							}else{ 	$date=array("message"=>"Your User Name or PassWord isn't correct!2")	;								
										$this->load->view("client/login",$date); }
				
								}else{$date=array("message"=>"")	;								
										$this->load->view("client/login",$date);}
					
								}else 
									{
//enter CMS directement
									redirect("client/product/mainpage","reflesh");
										echo $this->session->userdata("username");
									}
			
			}//function loginpro
	}//class
	
	

